/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bpmlab.kivulifx.application;

import bpmlab.kivulifx.entity.Project;
import bpmlab.kivulifx.entity.ShapeModel;
import bpmlab.kivulifx.util.DialogsCustom;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;

/**
 *
 * @author bpmlab
 */
public class Context {

    private static Context defaultContext;
    private final SimpleObjectProperty<Project> project;
    private final SimpleStringProperty workspace;
    private final Map<String, Project> projects;

    private Context() {
        this.workspace = new SimpleStringProperty();
        this.project = new SimpleObjectProperty<>();
        this.projects = new HashMap<>();
    }

    public void initContext() {
        DialogsCustom.workspace();
    }

    public void destroyContext() {
    }

    public void addShapeToCurrentProject(ShapeModel shape) {
        project.get().getShapes().add(shape);
    }

    public Map<String, Project> projects() {
        return projects;
    }

    public static Context getCurrentInstance() {
        if (defaultContext == null) {
            defaultContext = new Context();
        }
        return defaultContext;
    }

    public String getWorkspace() {
        return workspace.get();
    }

    public void setWorkspace(String file) {
        workspace.set(file);
    }

    public SimpleStringProperty workspaceProperty() {
        return workspace;
    }

    public void setCurrentProject(Project project) {
        this.project.set(project);
    }

    public Project currentProject() {
        return project.get();
    }

    public SimpleObjectProperty<Project> currentProjectProperty() {
        return project;
    }
}
